﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>呷饭网</title>
    <link rel="stylesheet" type="text/css" href="styles/mobile.css" />
    <link href="styles/jquery.ui.all.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.bgiframe-2.1.1.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.core.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.mouse.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.button.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.draggable.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.position.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.dialog.js"></script>
    <link href="styles/flexy-menu.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/flexy-menu.js"></script>
    <script type="text/javascript" src="scripts/common.js"></script>

    <style type="text/css">
        .validateTips
        {
            border: 0px solid transparent;
            padding: 0.3em;
        }
    </style>

    <script type="text/javascript">
        var PageFlag;
        $(function () {
            $(".flexy-menu").flexymenu({ speed: 100 });
            getUserInfo();
            getListData("");
            PageFlag = getParameter("PageFlag");
            $('.goback').click(function () {
                if (PageFlag == "1") {
                    window.location.href = "./manager.html";
                }
                else {
                    window.location.href = "./login.html";
                }
            });

            $("#OrderInfo").dialog("destroy");
            $("#OrderInfo").dialog({
                autoOpen: false,
                resizable: false,
                width: 300,
                height: 'auto',
                modal: true,
                position: ["center", "center"],
                buttons: {
                    "关 闭": function () {
                        $(this).dialog("close");
                    },
                    "确 定": function () {
                        closingOrder();
                    }
                }
            });
        });

        function getListData(flag) {
            getDineTableList(flag);
        }

        //获取酒店订单信息
        function getDineTableList(flag) {
            $("#tbllist").html("");

            if (flag == "Rooms") {
                $("#all").removeClass("active");
                $("#hall").removeClass("active");
                $("#rooms").addClass("active");
            }
            else if (flag == "Hall") {
                $("#all").removeClass("active");
                $("#rooms").removeClass("active");
                $("#hall").addClass("active");
            }
            else if (flag == "Add") {
                $("#all").removeClass("active");
                $("#rooms").removeClass("active");
                $("#hall").removeClass("active");
                $("#add").addClass("active");
            }
            else {
                $("#rooms").removeClass("active");
                $("#hall").removeClass("active");
                $("#all").addClass("active");
            }

            if (flag == "Add") {
                var datas = "&flag=" + flag;
                var url = "CommonPage.aspx?opration=getHandleType" + datas;
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: 'json',
                    success: function (data) {
                        if (data.Success) {
                            $(".tips")[0].style.display = "none";
                            for (var i = 0, str = ''; i < data.List.length; i++) {
                                if (data.List[i].OrderId == "") {
                                    str += "<tr style='height:10px;'><td class='l'>" + data.List[i].Name + "<br/>(" + data.List[i].Category + ")</td><td class='c' style='vertical-align:middle'>可坐人数：" + data.List[i].Numbers + "人</td><td class='r' style='vertical-align:middle'><a href='#' name='" + data.List[i].Name + "' dir='" + data.List[i].Category + "' onclick='openDineTable(this," + data.List[i].HotelId + "," + data.List[i].SeatId + ",\"cashier.html\",3);'>开台</a></td></tr>";
                                }
                            }
                            $("#tbllist").html(str);
                        }
                        else {
                            if (data.Url != "") {
                                updateTip(data.Msg, true, "URL", data.Url);
                            }
                            else {
                                $(".tips")[0].style.display = "";
                                $("#msgtip").text(data.Msg);
                            }
                        }
                    }
                });
            }
            else {
                var datas = "&flag=" + flag;
                var url = "CommonPage.aspx?opration=getCashierList" + datas;
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: 'json',
                    success: function (data) {
                        if (data.Success) {
                            $(".tips")[0].style.display = "none";
                            for (var i = 0, str = ''; i < data.List.length; i++) {
                                if (data.List[i].TableState == 0 && data.List[i].OrderState == 4) {
                                    str += "<tr><td class='l'>" + data.List[i].Name + "</td><td class='l'>" + data.List[i].Category + "</td><td class='c'>" + data.List[i].RoomNumber + "</td><td class='c'><b>￥" + data.List[i].TotalPrice + "</b></td><td class='r'><a href='#' style='width:65px;' onclick=\"OrderPaying('" + data.List[i].OrderId + "','" + data.HotelId + "','" + data.UserId + "','" + data.UserPwd + "','" + data.List[i].Token + "');\">结账</a></td></tr>";
                                }
                                else if (data.List[i].TableState == 1 && data.List[i].OrderState == 4) {
                                    str += "";
                                }
                                else if (data.List[i].TableState == 0 && data.List[i].OrderState == 5 || data.List[i].OrderState == 7) {
                                    str += "<tr><td class='l'>" + data.List[i].Name + "</td><td class='l'>" + data.List[i].Category + "</td><td class='c'>" + data.List[i].RoomNumber + "</td><td class='c'><b>￥" + data.List[i].TotalPrice + "</b></td><td class='r'><a href='#' style='width:65px;' onclick='cleanDineTable(" + data.List[i].OrderId + "," + data.List[i].DineTableId + ");'>清台</a></td></tr>";
                                }
                                else {
                                    $(".tips")[0].style.display = "";
                                    $("#msgtip").text("没有查询到相关数据！");
                                }
                            }
                            $("#tbllist").html(str);
                        }
                        else {
                            if (data.Url != "") {
                                updateTip(data.Msg, true, "URL", data.Url);
                            }
                            else {
                                $(".tips")[0].style.display = "";
                                $("#msgtip").text(data.Msg);
                            }
                        }
                    }
                });
            }
        }

        //结账.Begin
        function OrderPaying(OrderId, HotelId, UserId, UserPwd, Token) {
            var datas = "orderid=" + OrderId + "&hid=" + HotelId + "&uid=" + UserId + "&upassword=" + UserPwd + "&token=" + Token;
            var url = "http://hotel.xiafanwang.com/Settlement/HotelApp/CheckOut?" + datas;
            $('<iframe frameborder="0" src="' + url + '"/>').dialog({
                autoOpen: true,
                resizable: false,
                width: 380,
                height: 320,
                //modal: true,
                show: "blind",
                hide: "explode",
                position: ["center", "center"],
                buttons: {
                    "关 闭": function () {
                        $(this).dialog("close");
                        getListData("")
                    }
                }
            }).width(370).height(310);

            //$("#divOrder").dialog({
            //    autoOpen: true,
            //    resizable: false,
            //    width: 380,
            //    height: 350,
            //    height: 'auto',
            //    modal: true,
            //    position: ["center", "center"],
            //    open: function(ev, ui){  
            //        $('#iframeOrder').attr('src',url);  
            //    }, 
            //    buttons: {
            //        "关 闭": function () {
            //            $(this).dialog("close");
            //        },
            //        "确 定": function () {
            //            closingOrder();
            //        }
            //    }
            //});
        }

        function showOrderInfos(OrderId, DineTableId, U_Id, OrderAmount) {
            $("#hide_OrderId").val(OrderId);
            $("#hide_DineTableId").val(DineTableId);
            $("#hide_U_Id").val(U_Id);
            $("#OrderAmount")[0].innerHTML = OrderAmount;
            //$("#PayAmount")[0].innerHTML = OrderAmount;
            $("#DisAmount").val("0");
            $("#RecAmount").val("0");
            $("#RecAmount").removeClass('ui-state-error');
            $("#AccAmount").val("0");

            if (U_Id == "-1") {
                $("#One")[0].style.display = "";
                $("#Two")[0].style.display = "none";
            }
            else {
                $("#One")[0].style.display = "none";
                $("#Two")[0].style.display = "";
            }
            $("#OrderInfo").dialog('open');
        }
        function closingOrder() {
            var OrderAmount = $("#OrderAmount"),//应付金额
                DisAmount = $("#DisAmount"),//优惠金额
                RecAmount = $("#RecAmount"),//已收金额
                AccAmount = $("#AccAmount"),//应找金额

            allFields = $([]).add(RecAmount).add(AccAmount).add(DisAmount);
            var bValid = true;
            allFields.removeClass('ui-state-error');

            //bValid = bValid && checkRegexp(DisAmount, /.+/, "请输入优惠金额！");
            bValid = bValid && checkRegexp(RecAmount, /.+/, "请输入实收金额！");
            //bValid = bValid && checkRegexp(AccAmount, /.+/, "请输入应找金额！");

            //bValid = bValid && checkRegexp(DisAmount, /^[-\+]?\d+(\.\d+)?$/, "请输入正确的金额！");
            bValid = bValid && checkRegexp(RecAmount, /^[-\+]?\d+(\.\d+)?$/, "请输入正确的实收金额！");
            //bValid = bValid && checkRegexp(AccAmount, /^[-\+]?\d+(\.\d+)?$/, "请输入正确的金额！");

            //if (parseFloat(RecAmount.val()) < parseFloat(OrderAmount[0].innerHTML)) {
            //updateTip("实收金额不能小于应付金额！", false, "", "");
            //bValid = false;
            //}
            //if (parseFloat(DisAmount.val()) >= parseFloat(OrderAmount[0].innerHTML)) {
            //updateTip("优惠金额不能大于等于应付金额！", false, "", "");
            //bValid = false;
            //}
            if (parseFloat(RecAmount.val()) <= 0) {
                updateTip("实收金额不能小于或等于0！", false, "", "");
                bValid = false;
            }

            if (bValid) {
                var datas = "&U_Id=" + $("#hide_U_Id").val() + "&OrderId=" + $("#hide_OrderId").val() + "&DineTableId=" + $("#hide_DineTableId").val() + "&OrderAmount=" + OrderAmount.text() + "&DisAmount=" + DisAmount.val() + "&RecAmount=" + RecAmount.val() + "&AccAmount=" + AccAmount.val();
                var url = "CommonPage.aspx?opration=OrderPaying" + datas;
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: 'json',
                    success: function (data) {
                        if (data.Success) {
                            $("#OrderInfo").dialog("close");
                            updateTip(data.Msg, true, "Method", "");
                        }
                        else {
                            updateTip(data.Msg, false, "", "");
                        }
                    }
                });
            }
        }
        function checkRegexp(o, regexp, n) {
            if (!(regexp.test(o.val()))) {
                o.addClass('ui-state-error');
                updateTip(n, false, "", "");
                return false;
            } else {
                return true;
            }
        }
        //结账.End

        //清台(功能作废)
        function cleanDineTable(OrderId, DineTableId) {
            $(".dialogTip").text("是否清理此桌位？")
            $("#dialog").dialog({
                resizable: false,
                height: 120,
                modal: true,
                position: ["center", "center"],
                buttons: {
                    "关 闭": function () {
                        $(this).dialog("close");
                    },
                    "确 定": function () {
                        var datas = "&OrderId=" + OrderId + "&DineTableId=" + DineTableId;
                        var url = "CommonPage.aspx?opration=cleanDineTable" + datas;
                        $.ajax({
                            url: url,
                            type: "post",
                            dataType: 'json',
                            success: function (data) {
                                $(this).dialog("close");
                                if (data.Success) {
                                    updateTip(data.Msg, true, "Method", "");
                                }
                                else {
                                    if (data.Url != "") {
                                        updateTip(data.Msg, true, "URL", data.Url);
                                    }
                                    else {
                                        updateTip(data.Msg, false, "", "");
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }

        //校验是否为数字
        function IsNumber() {
            if (event.keyCode == 46)
                return true;
            if (event.keyCode < 48 || event.keyCode > 57) {
                event.returnValue = false;
            }
        }

        //应付金额(功能作废)
        function calPay() {
            if ($("#DisAmount").val() != "0" && $("#DisAmount").val() != "" && $("#DisAmount").val() != "NaN") {
                if (parseFloat($("#OrderAmount").text()) < parseFloat($("#DisAmount").val())) {
                    updateTip("优惠金额不能大于菜单合计！", false, "", "");
                    $("#DisAmount").val("0");
                    $("#PayAmount").text($("#OrderAmount").text());
                }
                else {
                    $("#PayAmount").text(parseFloat($("#OrderAmount").text()) - parseFloat($("#DisAmount").val()));
                    if ($("#RecAmount").val() != "0" && $("#RecAmount").val() != "" && $("#RecAmount").val() != "NaN" && parseFloat($("#RecAmount").val()) >= parseFloat($("#PayAmount").text())) {
                        $("#AccAmount").val(parseFloat($("#RecAmount").val()) - parseFloat($("#PayAmount").text()));
                    }
                }
            }
            else {
                if ($("#RecAmount").val() != "0" && $("#RecAmount").val() != "" && $("#RecAmount").val() != "NaN" && parseFloat($("#RecAmount").val()) >= parseFloat($("#PayAmount").text())) {
                    $("#AccAmount").val(parseFloat($("#RecAmount").val()) - parseFloat($("#PayAmount").text()));
                }
            }
        }
        //应找金额
        function calAcc() {
            if ($("#RecAmount").val() != "" && $("#RecAmount").val() != null) {
                if (parseFloat($("#RecAmount").val()) > parseFloat($("#OrderAmount").text())) {
                    $("#DisAmount").val("0");
                    $("#AccAmount").val(parseFloat($("#RecAmount").val()) - parseFloat($("#OrderAmount").text()));
                }
                else {
                    $("#DisAmount").val(parseFloat($("#OrderAmount").text()) - parseFloat($("#RecAmount").val()));
                    $("#AccAmount").val("0");
                }
            }
            else {
                $("#DisAmount").val("0");
                $("#AccAmount").val("0");
            }
        }
    </script>
</head>

<body>
    <div class="wrapall">
        <table class="topbar">
            <tr>
                <td class="l"><a class="goback">返回</a></td>
                <td class="c" id="H_Name"></td>
                <td class="r" align="right">
                    <ul class="flexy-menu">
                        <li id="lilist"></li>
                    </ul>
                </td>
            </tr>
        </table>
        <table class="tab1">
            <tr>
                <td class="active" id="all"><a href="#" onclick="getDineTableList('');">全部</a></td>
                <td id="rooms"><a href="#" onclick="getDineTableList('Rooms');">包厢</a></td>
                <td id="hall"><a href="#" onclick="getDineTableList('Hall');">大厅</a></td>
                <td id="add"><a href="#" onclick="getDineTableList('Add');">开台</a></td>
            </tr>
        </table>
        <table class="tbllist" id="tbllist">
        </table>
        <span class="tips" style="display: none;"><i></i><b id="msgtip"></b>

        </span>
        <br />
    </div>
    <div id="dialog" title="提示信息" style="text-align: center; vertical-align: middle;">
        <p class="dialogTip"></p>
    </div>
    <!--<div id="OrderInfo" title="结账列表">
        <table class="tbllist">
            <tr>
                <td>就餐人数：</td>
                <td class="c">
                    <input type="text" id="dineNum" value="0" style="width: 50px; vertical-align: top;" /></td>
            </tr>
            <tr>
                <td>菜单合计：</td>
                <td class="c"><b>￥</b><b id="OrderAmount"></b></td>
            </tr>
            <tr>
                <td>实收金额：</td>
                <td class="c">
                    <input type="text" id="RecAmount" value="0" style="width: 50px; vertical-align: top;" onkeyup="calAcc()" onkeypress="javascript:IsNumber()" /></td>
            </tr>
            <tr id="One" style="display: none;">
                <td>优惠金额：</td>
                <td class="c">
                    <input type="text" id="DisAmount" value="0" readonly="readonly" style="width: 50px; vertical-align: top;" /></td>
            </tr>
            <tr>
                <td>应找金额：</td>
                <td class="c">
                    <input type="text" id="AccAmount" value="0" readonly="readonly" style="width: 50px; vertical-align: top;" /></td>
            </tr>
            <tr id="Two" style="display: none;">
                <td>
                    <table class="tbllist" id="tblCouponList">
                    </table>
                </td>
            </tr>
        </table>
    </div>-->
    <div id="divOrder" title="结账列表" style="display:none;">
        <iframe frameborder="0" id="iframeOrder" src=""></iframe>
    </div>
    <input type="hidden" id="hide_U_Id" value="" />
    <input type="hidden" id="hide_OrderId" value="" />
    <input type="hidden" id="hide_DineTableId" value="" />
</body>
</html>
